import axios from 'axios'
import { Connect } from './apiUrl'
let qs = require('qs')

var baseURL = Connect.baseURL

// 请求带cookie
axios.defaults.withCredentials = true

//=============================================================普通form表单提交👇==================================================//
// form提交
let formPost = axios.create({
	baseURL,
	headers: {
		'Content-Type': 'application/x-www-form-urlencoded;charset=UTF-8',
    'Accept-Language': 'zH-CN',
	},
	method: 'post',
})

formPost.interceptors.response.use(
	function(response) {
		let re = response.data
		showResult(re)
		return re
	},
	function(error) {
		alert('您的网络可能有问题,请退出登录检查网络')
		return false
	},
)

let vpost = (link, setting) => {
	let s = qs.stringify(setting)
	// showResult(s)
	return formPost.post(link, s)
}
//=============================================================普通form表单提交👆==================================================//

//=============================================================JSON字符串提交👇==================================================//
// json格式
let jpost = axios.create({
	baseURL,
	headers: {
		'Content-Type': 'application/json;charset=UTF-8',
    'Accept-Language': 'zH-CN',
	},
	method: 'post',
})

jpost.interceptors.response.use(
	function(response) {
		let re = response.data
		showResult(re)
		return re
	},
	function(error) {
		alert('您的网络可能有问题,请退出登录检查网络')
		return false
	},
)

let sonpost = (link, setting) => {
	// showResult(setting)
	return jpost.post(link, setting)
}
//=============================================================JSON字符串提交👆==================================================//

//=============================================================带文件提交👇==================================================//

// 文件格式
let filePost = axios.create({
	baseURL,
	headers: {
		'Content-Type': 'multipart/form-data',
    'Accept-Language': 'zH-CN',
	},
	method: 'post',
})

filePost.interceptors.response.use(
	function(response) {
		let re = response.data
		showResult(re)
		return re
	},
	function(error) {
		alert('您的网络可能有问题,请退出登录检查网络')
		return false
	},
)

let fpost = (link, setting) => {
	// let s = qs.stringify(setting)
	// showResult(s)
	return filePost.post(link, setting)
}
//=============================================================带文件提交👆==================================================//

//=============================================================Get请求获取数据👇==================================================//
// form提交
let GetPost = axios.create({
	baseURL,
	headers: {
		'Content-Type': 'application/json;charset=UTF-8',
    'Accept-Language': 'zH-CN',
	},
	method: 'get',
})

GetPost.interceptors.response.use(
	function(response) {
		let re = response.data
		showResult(re)
		return re
	},
	function(error) {
		alert('您的网络可能有问题,请退出登录检查网络')
		return false
	},
)

let gpost = (link, setting) => {
	let s = qs.stringify(setting)
	showResult(s)
	return GetPost.get(link, s)
}
//=============================================================Get请求获取数据👆==================================================//

// 测试环境用来看请求的结果
let showResult = re => {
	// console.log(re)
}

// ===========================================================API接口👇=====================================================//
let vlink = {
	sign: {
		in: 'app/oauth/token', //登录接口
		smssend: 'app/sendValidateCode', //短信验证码发送
		up: 'app/register', //注册接口
		forget: 'app/user/forgetPasswd', //忘记密码
		forgetSMSSend: 'app/sendFindPassWordCode', //忘记密码短信验证发送
	},
	imgCode: baseURL + 'servlet/ValidateImageServlet/', //图片验证码
	user: {
		info: 'my/getUserInf', //用户详细信息接口
		tel: 'my/replacePhone', //跟换绑定手机号接口
		inPwd: 'my/replaceLoginPassword', //修改登录密码
		identity: 'my/addBankBefor', //查询用户身份
		pay: 'my/replaceTradePassword', //修改支付密码
	},
	card: {
		info: 'my/bankList', //用户银行卡列表
		keep: 'my/addBank', //保存银行卡接口
	},
	balance: 'my/assets/get', //查询用户余额
	integral: 'my/assets/findIntegralByUser', //查询用户积分
	mate: {
		select: 'my/friend/list', // 查询好友
		selectChatHis: 'my/friend/getChatRecord', //查询聊天记录
	},
	auction: {
		length: 'my/activity/auctionAllStatistics', //查询所有商品记录长度
		all: 'my/activity/auctionAll', //用户全部商品记录
		current: 'my/activity/auctionRecording', //我在拍
		delivery: 'my/activity/pendingDelivery', //等待发货
		collect: 'my/activity/waitSignIn', //等待签收
		complete: 'my/activity/signIn', //已完成
		info: 'my/activity/getLogisticsInformation', // 获得物流信息
	},
	carry: 'my/assets/integralAvailable', //转账 积分||余额
	cash: 'my/assets/putForward', //提现
	fee: 'my/assets/getshow', //用户提现 计算手续费 实际到账
	home: {
		banner: 'app/sowingBanner', //首页轮播图
		noticeTile: 'app/selectNoticeTitle', //首页公告标题
		noticeContent: 'app/selectNotice', //首页公告内容
		suggest: 'app/recommends', //首页推荐产品
		hot: 'app/hotSelling', //首页热卖商品
		ad: 'advertise/showAdvertise', //首页广告
	},
	address: {
    add: 'my/addAddress', //添加用户地址
		getThreeAddress: 'my/getarea', //获取三级联动地址
		saveAddress: 'my/ygreceivingaddress', //添加收货地址
		getAddress: 'my/addressList', //获取个人收货地址
		editDefault: 'my/setDefaultAddress', //修改默认地址
	},
	recharge: {
		submitRecharge: 'my/balanceRecharge', //通过支付宝提交充值金额创建订单
		subWithWeChat: 'wx/unifiedOrder', //通过微信提交充值金额创建订单
		alipay: 'unifiedOrder', //唤起支付宝支付
	},
	detail: {
		countDown: 'app/goodsDynamic/', //参与商品详情页(倒计时)
		data: 'app/goodsAuction/', //参与商品详情页(静态数据)
		bid: 'app/goodsAuctionLog/', //参与商品详情页(出价记录)
	},
	latestDeal: 'app/latestDeal', //最新成交接口
	classify: 'item-cats/getJsonTree/', //分类
	dealDetail: 'app/goodsDynamicDeal/', //最新成交详情页
	collection: 'collectionByUser', // 用户收藏
	currentTime: 'my/activity/getTime',//当前系统时间
	goodsList: 'app/goodsSearch',//商品检索(商品名或分类)
	goods: 'item-cats/goods',//查询该类别的商品商品
  convert: {
    list: 'app/exchange/showAllGoodsExchange',//兑换列表
    detail: 'app/exchange/showGoodsExchangeRecord/',//兑换详情
    record: 'app/exchange/showAllGoodsExchangeRecord',//兑换记录
  },
  hotSearch: 'app/goodsSearchValue',//热门搜索
}
// ===========================================================API接口👆=====================================================//

export { vpost, sonpost, fpost, gpost, vlink }
